<?php
class AdminController extends BaseController {
	
	public $display;
	
	public function adminEmployee(){
		//get employees
		$this->getEmployeeList();
		
		//get branch
		$this->getBranchList();
		
		//get position
		$this->getPositionList();
		
		//get employeeStatus
		$this->getStatusList();
		
		$this->view->template('pages/admin/adminEmployee');
	}
	
	public function getEmployeeList(){
		$adminService = new AdminService();
		$employees = $adminService->getEmployees();
		
		$this->view->setDisplay('employees', $employees);
	}
	
	public function getBranchList(){
		$adminService = new AdminService();
		$branches = $adminService->getBranches();
		
		$this->view->setDisplay('branch', $branches);
	}
	
	public function getPositionList(){
		$adminService = new AdminService();
		$positions = $adminService->getPositions();
		
		$this->view->setDisplay('position', $positions);
	}
	
	public function getStatusList(){
		$adminService = new AdminService();
		$status = $adminService->getStatus();
		
		$this->view->setDisplay('status', $status);
	}
	
	public function getEmployee(){
		$result = array();
		
		$adminService = new AdminService();
		$employee = $adminService->getEmployeeById($this->post('employeeId'));
			
		$result["employeeId"] = $employee->getEmployeeId();
		$result["firstname"] = $employee->getFirstName();
		$result["lastname"] = $employee->getLastName();
		$result["address"] = $employee->getAddress();
		$result["hiredate"] = $employee->getHiredate();
		$result["contact"] = $employee->getContactNumber();
		$result["position"] = $employee->getPosition();
		$result["branch"] = $employee->getBranch();
		$result["status"] = $employee->getStatus();
		
		echo json_encode($result);
	}
	
	public function updateEmployee(){
		$result = array();
		
		$adminService = new AdminService();
		$employee = new Employee_Domain();
		
		$employee->setEmployeeId($this->post('employeeId'));
		$employee->setFirstName($this->post('firstname'));
		$employee->setLastName($this->post('lastname'));
		$employee->setAddress($this->post('address'));
		$employee->setHiredate($this->post('hiredate'));
		$employee->setContactNumber($this->post('contact'));
		$employee->setPosition($this->post('position'));
		$employee->setBranch($this->post('branch'));
		$employee->setStatus($this->post('status'));
		
		$result["rowsAffected"] = $adminService->updateEmployee($employee);
		echo json_encode($result);
	}
	
	public function saveEmployee(){
		$adminService = new AdminService();
		$employee = new Employee_Domain();
		
		$employee->setFirstName($this->post('firstname'));
		$employee->setLastName($this->post('lastname'));
		$employee->setAddress($this->post('address'));
		$employee->setHiredate($this->post('hiredate'));
		$employee->setContactNumber($this->post('contact'));
		$employee->setPosition($this->post('position'));
		$employee->setBranch($this->post('branch'));
		
		$result["rowsAffected"] = $adminService->saveEmployee($employee);
		echo json_encode($result);
	}
	
	public function myAccount(){
		$this->view->template('pages/admin/myAccount');
	}
	
	public function updateAccount(){
		$adminService = new AdminService();
		$employee = new Employee_Domain();
		
		$employee->setEmployeeId($_SESSION['employee']->getEmployeeId());
		$employee->setPassword($this->post('password'));
		$result["rowsAffected"] = $adminService->updateAccount($employee);
		echo json_encode($result);
	}
	

	
}